package com.framework.boc.statistics.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.framework.boc.response.CommonResponse;
import com.framework.boc.statistics.entity.StatisticalBatch;
import com.framework.boc.statistics.request.vo.PageCondition;
import com.framework.boc.statistics.service.impl.StatisticalBatchServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.framework.boc.controller.BaseController;

/**
 * <p>
 * 统计批次表 前端控制器
 * </p>
 *
 * @author Leil
 * @since 2020-12-23
 */
@RestController
@RequestMapping("/statistics/statistical-batch")
public class StatisticalBatchController extends BaseController {

    @Autowired
    StatisticalBatchServiceImpl statisticalBatchService;

    @PostMapping("/save")
    public CommonResponse save(@RequestBody StatisticalBatch batch) {
        boolean bool = this.statisticalBatchService.addOrUpdate(batch);
        return bool ? CommonResponse.success("保存成功") : CommonResponse.error("保存失败");
    }

    @PostMapping("/page")
    public CommonResponse page(@RequestBody PageCondition<StatisticalBatch> condition) {
        Page<StatisticalBatch> page = new Page<>(condition.getCurrent(), condition.getSize());
        LambdaQueryWrapper<StatisticalBatch> wrapper = Wrappers.lambdaQuery(condition.getCondition());
        IPage<StatisticalBatch> res = this.statisticalBatchService.page(page, wrapper);
        return CommonResponse.success(res);
    }

}

